/*
 * bitbanding.h
 *
 *  Created on: May 26, 2011
 *
 *  Omnima Limited
 *
 *  Targets STM32L family MCUs as used 
 *  on the omnima-stm32-expander board
 *
 */

#ifndef BITBANDING_H_
#define BITBANDING_H_

#define BITBAND_SRAM_REF   0x20000000
#define BITBAND_SRAM_BASE  0x22000000
#define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + (a-BITBAND_SRAM_REF)*32 + (b*4)))  // Convert SRAM address

#define BITBAND_PERI_REF   0x40000000
#define BITBAND_PERI_BASE  0x42000000
#define BITBAND_PERI(a,b) ((BITBAND_PERI_BASE + (a-BITBAND_PERI_REF)*32 + (b*4)))  // Convert PERI address

#define GPIOA_BB(b) *((volatile uint8_t *)(BITBAND_PERI(0x40020014,b)))
#define GPIOB_BB(b) *((volatile uint8_t *)(BITBAND_PERI(0x40020414,b)))
#define GPIOC_BB(b) *((volatile uint8_t *)(BITBAND_PERI(0x40020814,b)))
#define GPIOD_BB(b) *((volatile uint8_t *)(BITBAND_PERI(0x40020C14,b)))

#define MAILBOX   0x20004000
#define TIMER     0x40004000
//#define MBX_B0    *((volatile unsigned int *)(BITBAND_SRAM(MAILBOX,0))) // Bit 0
//#define MBX_B7    *((volatile unsigned int *)(BITBAND_SRAM(MAILBOX,7))) // Bit 7
//#define TIMER_B0  *((volatile unsigned char *)(BITBAND_PERI(TIMER,0)))  // Bit 0
//#define TIMER_B7  *((volatile unsigned char *)(BITBAND_PERI(TIMER,7)))  // Bit 7

#endif /* BITBANDING_H_ */
